package b1.scenes.home
{
	import b1.net.*;
	import b1.players.*;
	import b1.utils.*;
	import b1.scenes.suspect.*;
	
	import com.greensock.TweenLite;
	import com.greensock.easing.Expo;
	
	import flash.display.Sprite;
	import flash.text.*;

	public class CaseEstablishDialog extends Sprite
	{
    	private var container:Sprite;
    	
		public function CaseEstablishDialog(battleCase:BattleCaseInfo)
		{
			super();
			
			container = new Sprite();
			//背景
			var ArrestDialogBgr:Class = ResourceHelper.getInstance().getClassByName("CaseFile");
			var dialogSprite:Sprite = new ArrestDialogBgr();
			container.addChild(dialogSprite);
			
			//标题名字
			var titleText:TextField = new TextField();
			titleText.wordWrap = true;
			titleText.selectable = false;
        	titleText.autoSize = TextFieldAutoSize.LEFT;
			titleText.defaultTextFormat = new TextFormat("微软雅黑", 18, 0x000000);
			titleText.width = 220;
			titleText.text = "天网恢恢，肥而不腻！你在犯罪现场掉落了以下证物，已经被立案侦查。";
			titleText.x = 130;
			titleText.y = 60;
			container.addChild(titleText);
			
			//掉落的证据
			for (var i:int = 0; i < battleCase.clues.length; i++)
			{
				var clueItem:ClueItem = new ClueItem(battleCase.clues[i]);
				clueItem.x = 170;
				clueItem.y = i * 100 + 150;
				container.addChild(clueItem);
			}
			
			//印章
			TweenLite.delayedCall(1, addStamp);
			container.x = -container.width / 2;
			container.y = -container.height / 2;
			addChild(container);
		}
		
		private function addStamp():void
		{
			var StampImage:Class = ResourceHelper.getInstance().getClassByName("EstablishCaseStamp");
			var stamp:Sprite = new StampImage();
			stamp.x = -100;
			stamp.y = -100;
			stamp.scaleX = 4;
			stamp.scaleY = 4;
			var targetScale:Number = 0.5;
			container.addChild(stamp);
			TweenLite.to(stamp, 0.8, {x:250, y:280, scaleX:targetScale, scaleY:targetScale, rotation: -10, ease:Expo.easeIn, onComplete:onStampMovieComplete});
		}
		
		private function onStampMovieComplete():void
		{
			TweenLite.to(this, 1.5, {delay:4, x:BFont.stageWidth - 30, y:35, scaleX:0.01, scaleY:0.01, rotation: 720, onComplete:onRotateMovieComplete});
		}
		
		private function onRotateMovieComplete():void
		{
			close();
		}
		
		public function close():void
		{
			if (this.parent != null)
				this.parent.removeChild(this);
		}
		
	}
}